<?php
abstract class FShape
{
    protected $color = null;
    public function __construct(IColor $color)
    {
        $this->color = $color;
    }
    public function shape()
    {
        echo $this->color->color() . $this->setShape() . PHP_EOL;
    }
    protected abstract function setShape();
}

class CircleShape extends FShape
{
    protected function setShape()
    {
        return '圆形';
    }
}

class SquareShape extends FShape
{
    protected function setShape()
    {
        return '正方形';
    }
}

interface IColor
{
    public function color();
}

class BlueColor implements IColor
{
    public function color()
    {
        return '蓝色';
    }
}

class RedColor implements IColor
{
    public function color()
    {
        return '红色';
    }
}

/**
 * 桥接模式后，我们的代码就符合了“开闭原则”， 当有新的形状或颜色加入时，
 * 我们只需要添加新的类即可。而不用去修改之前的类。
 */

$blueColor = new BlueColor();
$redColor = new RedColor();
$blueCircleShape = new CircleShape($blueColor);
$redCircleShape = new CircleShape($redColor);
$blueSquareShape = new SquareShape($blueColor);
$redSquareShape = new SquareShape($redColor);

$blueCircleShape->shape();
$redCircleShape->shape();
$blueSquareShape->shape();
$redSquareShape->shape();
